#!/usr/bin/env python
#
import os
import sys

from ctypeslib import h2xml, xml2py

def main(hdr_file, lib_file):

    package_dir = 'fitsio'

    xml_file = os.path.join(package_dir, '_cfitsio.xml')
    argv = ['h2xml.py', hdr_file, '-q', '-c', '-o', xml_file]

    # Convert .h file into xml file
    h2xml.main(argv)

    py_file = os.path.join(package_dir, '_cfitsio.py')

    # This results in "unresolved alias" errors, but things seem to work OK
    # No errors are generated if the -kdfst switch is used, but the I can't 
    # access the full CFITSIO function aliases (only the short names).
    argv = ['xml2py.py', xml_file, '-l', lib_file, '-o', py_file]

    # Convert xml file into python file
    xml2py.main(argv)

if __name__ == '__main__':
    
    # Modify these, if necessary, for your system
    hdr_file = '/usr/local/include/fitsio.h'
    lib_file = '/usr/local/lib/libcfitsio.so'

    main(hdr_file, lib_file)
